#include <bits/stdc++.h>
using namespace std;
using uint=unsigned int;
using ll=long long;
using ull=unsigned long long;
using i128=__int128;
const int MAX=1e6+5;

struct qr{
    int q;
    int r;
};
struct td{
    int t;
    int d;
};

int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    int N;
    cin>>N;
    vector<qr> arrqr(N+1);
    for(int i=1;i<=N;i++){
        cin>>arrqr[i].q>>arrqr[i].r;
    }
    int Q;
    cin>>Q;
    vector<td> arrtd(Q+1);
    for(int i=1;i<=Q;i++){
        cin>>arrtd[i].t>>arrtd[i].d;
        int t = arrtd[i].t;
        int q = arrqr[t].q;
        int r = arrqr[t].r;
        
        int mod=(arrtd[i].d-r)%q;
        if(mod<0)mod+=q;
        
        if(mod == 0) {
            cout << arrtd[i].d << endl;
        } else {
            cout << arrtd[i].d + (q - mod) << endl;
        }
    }

    return 0;
}